package com.luke.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;

/**
 * @Descrtption RestTemplateController
 * @Author luke
 * @Date 2020/4/28
 **/
@Slf4j
@RestController
public class RestTemplateController {

    /**提供者服务cloud-eureka-client地址*/
    public static final String EUREKA_SERVICE_URL = "http://cloud-eureka-client";

    @Resource
    private RestTemplate restTemplate;

    /**
     * 使用RestTemplate+Ribbon 远程调用 cloud-eureka-client 服务
     * @param name
     * @return
     */
    @GetMapping("/consumer/sayHello/{name}")
    public String consumerSayHello(@PathVariable("name") String name) {
        return restTemplate.getForObject(EUREKA_SERVICE_URL+"/sayHello/"+name,String.class);
    }

}
